package com.gufe.service.admin.impl.datascreen;

import com.gufe.entity.RightCenterDataMain;
import com.gufe.mapper.admin.datascreen.RightChartMapper;
import com.gufe.service.admin.datascreen.RightChartService;
import com.gufe.vo.datascreen.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class RightChartServiceImpl implements RightChartService {

    @Autowired
    private RightChartMapper rightChartMapper;

    // 获取数据大屏右上角数据
    public List<RightTopDataVO> getRightTopData() {
        List<RightTopDataVO> rightTopData =  rightChartMapper.getRightTopData();
        for (RightTopDataVO item : rightTopData) {
            String originalDate = item.getEnlistmentDate();
            if (originalDate != null && originalDate.contains("-")) {
                // 截取年份部分（格式为 "YYYY-MM-DD"）
                String year = originalDate.substring(0, 4);
                item.setEnlistmentDate(year);
            }
        }
        return rightTopData;
    }

    // 获取数据大屏右中数据
    public List<RightCenterDataVO> getRightCenterData(Integer gender) {
        return rightChartMapper.getRightCenterData(gender);
    }

    // 获取数据大屏右下角数据
    public List<RightBottomDataVO> getRightBottomData() {

        List<RightBottomDataVO> rightBottomData = rightChartMapper.getRightBottomData();
        for (RightBottomDataVO rightBottomDatum : rightBottomData) {
            rightBottomDatum.setClubMembers(rightChartMapper.getClubMembers(rightBottomDatum.getYear()));
        }
        return rightBottomData;
    }

    // 获取数据大屏右下角大图数据
    public List<RightBottomMainDataVO> getRightBottomMainData() {
        return rightChartMapper.getRightBottomMainData();
    }

    @Override
    public List<RightCenterDataMainVO> getRightCenterMainData() {
        List<RightCenterDataMain> rightCenterDataMains = rightChartMapper.getRightCenterMainData();
        return rightCenterDataMains.stream()
                .map(dto -> new RightCenterDataMainVO(
                        dto.getScope(),
                        dto.getMaleCount(),
                        dto.getFemaleCount()
                ))
                .collect(Collectors.toList());
    }
}
